﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.sjsbyes
{
    public partial class gglist : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                f_buildGrid();
            }
        }
        protected void f_buildGrid()
        {
            Hashtable htable = new Hashtable();
            DataSet ds = new DataReturn().ReturnData(htable, "sel_gglist_all");

            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dbRow in ds.Tables[0].Rows)
                    {
                        if (dbRow["EditUrl"] != null)
                        {
                            dbRow["EditUrl"] = "ggEdit.aspx?Command=Edit";
                        }

                        if (dbRow["ViewUrl"] != null)
                        {
                            dbRow["ViewUrl"] = "ggEdit.aspx?Command=View";
                        }
                    }
                }
                PostListS.DataSource = ds;
                PostListS.DataBind();
                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

            }
        }
        /// <summary>
        /// Callback异步加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void LCallBack_Callback(object sender, NickLee.Web.UI.CallBackEventArgs e)
        {
            SqlReadXml org = new SqlReadXml();
            try
            {
                #region 删除数据
                if (Usual.f_convertString(e.Parameters[0]) == "3")
                {
                    SqlReadXml Org = new SqlReadXml();
                    var allname = "";
                    var deptname = "";
                    try
                    {

                        var zid = Usual.f_convertString(e.Parameters[2]);
                        if (zid == "" || zid == null)
                        {

                        }
                        base.o_uiTable.Clear();
                        base.o_uiTable.Add("@ggid", zid);


                        Org.NotDoSQL("del_gglist_byid", base.o_uiTable);
                        this.f_buildGrid();

                    }
                    catch (System.Exception ee)
                    {


                        hfError.Value = lblProcesserMsg.Text = "删除数据失败!" + ee.Message;

                    }
                }

                else if (Usual.f_convertString(e.Parameters[0]) == "2")
                {
                    SqlReadXml Org = new SqlReadXml();//
                    var zid = Usual.f_convertString(e.Parameters[2]);
                    if (zid == "" || zid == null)
                    {
                        this.f_buildGrid();
                    }
                    else
                    {
                        string likes = e.Parameters[2].ToString();
                        likes = "%" + likes + "%";
                        Hashtable htable = new Hashtable();
                        htable.Add("@like", likes);
                        DataSet ds = Org.ReaderDataSet("sel_gglist_bylike", htable);
                        if (ds != null)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dbRow in ds.Tables[0].Rows)
                                {
                                    if (dbRow["EditUrl"] != null)
                                    {
                                        dbRow["EditUrl"] = "ggEdit.aspx?Command=Edit";
                                    }

                                    if (dbRow["ViewUrl"] != null)
                                    {
                                        dbRow["ViewUrl"] = "ggEdit.aspx?Command=View";
                                    }
                                }
                            }
                            PostListS.DataSource = ds;
                            PostListS.DataBind();
                            this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                        }
                        PostListS.DataSource = ds;
                        PostListS.DataBind();
                        this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], PostListS, 10);

                    }
                }

                else if (Usual.f_convertString(e.Parameters[0]) == "4")
                {
                    SqlReadXml Org = new SqlReadXml();
                    var allname = "";
                    var deptname = "";
                    try
                    {

                        var zid = Usual.f_convertString(e.Parameters[2]);
                        if (zid == "" || zid == null)
                        {

                        }
                        base.o_uiTable.Clear();
                        base.o_uiTable.Add("@ggid", zid);
                        Org.NotDoSQL("zuofei_gglist_byid", base.o_uiTable);


                        Hashtable htSum = new Hashtable();
                        htSum.Add("@ggid", zid);
                        DataSet dsSum = new SqlReadXml().ReaderDataSet("sel_gglist_byid", htSum);
                        if (dsSum.Tables[0].Rows.Count > 0)
                        {
                            string ggvalue = Convert.ToString(dsSum.Tables[0].Rows[0]["ggvalue"]);
                           // string GGHID = string.Empty;
                            //乡
                            if (ggvalue == "1")
                            {
                                ZuoFeiByGGID(zid, "sel_NongCunGGHID_byid");                               
                            }
                            //企业
                            else if (ggvalue == "2")
                            {
                                ZuoFeiByGGID(zid, "sel_QiYeGGHID_byid");                                
                            }
                            //社区
                            else if (ggvalue == "3")
                            {
                                ZuoFeiByGGID(zid, "sel_SheQuGGHID_byid");
                            }
                        }

                        this.f_buildGrid();
                    }
                    catch (System.Exception ee)
                    {
                        hfError.Value = lblProcesserMsg.Text = "作废数据失败!" + ee.Message;
                    }
                }
                #endregion
            }
            catch (System.Exception pexp)
            {
                throw (pexp);
            }
            //最后进行Grid数据查询并填充
            finally
            {
             
                LPanel.RenderControl(e.Output);
            }

            
        }

        

        protected string IsZuoFei(object iszuofei)
        {
            string zuofei = string.Empty;

            if (Convert.ToString(iszuofei) == "1")
            {
                zuofei = "<font color='red'>是</font>";
            }
            else 
            {
                zuofei = "否";
            }

            return zuofei;

        }
        void ZuoFei(string GGHID)
        {
            Hashtable htIsZuoFei = new Hashtable();
            htIsZuoFei.Add("@GGHID", GGHID);
            DataSet dsIsZuoFei = new SqlReadXml().ReaderDataSet("update_GGHTable_byid", htIsZuoFei);
        }
        private void ZuoFeiByGGID(string zid, string sql)
        {
            string GGHID = string.Empty;
            Hashtable htable = new Hashtable();
            htable.Add("@ggid", zid);
            DataSet dset = new SqlReadXml().ReaderDataSet(sql, htable);

            if (dset.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
                {
                    GGHID = Convert.ToString(dset.Tables[0].Rows[i]["GGHID"]);
                    ZuoFei(GGHID);
                }

            }
        }

    }
}